/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include ".\workcfgelement.h"

WorkCfgElement::WorkCfgElement(void)
{
	Initialize();
}

WorkCfgElement::~WorkCfgElement(void)
{
}

//---------------------------------------------------------------------------

WorkCfgElement& WorkCfgElement::operator = (WorkCfgElement& wceIn)
{
	phaseType  = wceIn.phaseType;
	methodType = wceIn.methodType;
	data       = wceIn.data;

	pos        = wceIn.pos;

	return (*this);
}

//---------------------------------------------------------------------------

void WorkCfgElement::Initialize(void)
{
	phaseType  = __wptNone;
	methodType = __wmtNone;
	data.Empty();

	pos        = 0;
}

//---------------------------------------------------------------------------

void WorkCfgElement::LoadFromPointer(WorkCfgElement* wceIn)
{
	if(wceIn==NULL){
		Initialize();
		return;
	}

	phaseType  = wceIn->phaseType;
	methodType = wceIn->methodType;
	data       = wceIn->data;

	pos        = wceIn->pos;
}

//---------------------------------------------------------------------------

CString WorkCfgElement::ToString(void)
{
	CString str;
	CString sss;

	str.Empty();

	sss.Format("%d", (int)phaseType);
	while(sss.GetLength()<3)
		sss += " ";
	str += sss;

	sss.Format("%d", (int)methodType);
	while(sss.GetLength()<3)
		sss += " ";
	str += sss;

	str += data;

	return str;
}

bool WorkCfgElement::FromString(CString strIn)
{
	CString str;
	CString sss;

	str = strIn;
	str = str.Trim();
	if(str.GetLength()<4) return false;

	sss = str.Left(3);
	phaseType = (WorkPhaseType)_tstoi(sss);

	sss = str.Mid(3, 3);
	methodType = (WorkMethodType)_tstoi(sss);

	if(str.GetLength()>6) data = str.Mid(6);
	else                  data.Empty();

	return true;
}

//---------------------------------------------------------------------------
